#!/bin/sh
if [ $# -eq 0 ]; then
    echo "no paramaters.."
	exit 0
elif [ $# -eq 1 ]; then
	param1=$1
	if [ "$param1" = "clean" ]; then
		echo "clean apps"
		rm -rf ./HFL8_DDU*.app
		exit 0  
	fi
	
	if [ "$param1" = "+libs" ]; then
		echo "add changfeng libs.."
		cp -r ./ChangfengLib ./TC1_left/HFL8_DDU_package/
		cp -r ./ChangfengLib ./TC1_right/HFL8_DDU_package/
		cp -r ./ChangfengLib ./TC2_left/HFL8_DDU_package/
		cp -r ./ChangfengLib ./TC2_right/HFL8_DDU_package/
		exit 0
	fi
	
	if [ "$param1" = "-libs" ]; then
		echo "delete changfeng libs.."
		rm -rf ./TC1_left/HFL8_DDU_package/ChangfengLib
		rm -rf ./TC1_right/HFL8_DDU_package/ChangfengLib
		rm -rf ./TC2_left/HFL8_DDU_package/ChangfengLib
		rm -rf ./TC2_right/HFL8_DDU_package/ChangfengLib
		exit 0
	fi
	
	echo "copy ddu"
	cp -r $(find ../HFL8_DDU/bin/* ! -name "config.ini") ./TC1_left/HFL8_DDU_package/HFL8_DDU/
	cp -r $(find ../HFL8_DDU/bin/* ! -name "config.ini") ./TC1_right/HFL8_DDU_package/HFL8_DDU/
	cp -r $(find ../HFL8_DDU/bin/* ! -name "config.ini") ./TC2_left/HFL8_DDU_package/HFL8_DDU/
	cp -r $(find ../HFL8_DDU/bin/* ! -name "config.ini") ./TC2_right/HFL8_DDU_package/HFL8_DDU/

	echo "pack apps.."
	cd ./TC1_left/
	tar -zcvf HFL8_DDU1_Left_V$1.app HFL8_DDU_package/
	mv HFL8_DDU1_Left_V$1.app ../

	cd ../TC1_right/
	tar -zcvf HFL8_DDU1_Right_V$1.app HFL8_DDU_package/
	mv HFL8_DDU1_Right_V$1.app ../

	cd ../TC2_left/
	tar -zcvf HFL8_DDU6_Left_V$1.app HFL8_DDU_package/
	mv HFL8_DDU6_Left_V$1.app ../

	cd ../TC2_right/
	tar -zcvf HFL8_DDU6_Right_V$1.app HFL8_DDU_package/
	mv HFL8_DDU6_Right_V$1.app ../
elif [ $# -eq 2 ]; then
	param1=$1
	if [ "$param1" = "pis" ]; then
		echo "update pis.."
		PISVersion=$2
		PISUpdateBasePath="IGM-update-TFS-$PISVersion"
		cp -r ../$PISUpdateBasePath/home/project/BYGK/* ./TC1_left/HFL8_DDU_package/BYGK/
		cp -r ../$PISUpdateBasePath/home/project/BYGK/* ./TC1_right/HFL8_DDU_package/BYGK/
		cp -r ../$PISUpdateBasePath/home/project/BYGK/* ./TC2_left/HFL8_DDU_package/BYGK/
		cp -r ../$PISUpdateBasePath/home/project/BYGK/* ./TC2_right/HFL8_DDU_package/BYGK/

		cp -r ../$PISUpdateBasePath/usr/lib/* ./TC1_left/HFL8_DDU_package/PISLib/
		cp -r ../$PISUpdateBasePath/usr/lib/* ./TC1_right/HFL8_DDU_package/PISLib/
		cp -r ../$PISUpdateBasePath/usr/lib/* ./TC2_left/HFL8_DDU_package/PISLib/
		cp -r ../$PISUpdateBasePath/usr/lib/* ./TC2_right/HFL8_DDU_package/PISLib/

		cp ../$PISUpdateBasePath/mnt/disk/rec.db ./TC1_left/HFL8_DDU_package/PISLib/
		cp ../$PISUpdateBasePath/mnt/disk/rec.db ./TC1_right/HFL8_DDU_package/PISLib/
		cp ../$PISUpdateBasePath/mnt/disk/rec.db ./TC2_left/HFL8_DDU_package/PISLib/
		cp ../$PISUpdateBasePath/mnt/disk/rec.db ./TC2_right/HFL8_DDU_package/PISLib/

		cp ../$PISUpdateBasePath/home/project/HFL8_DDU/alarmChannelConfig ./TC1_left/HFL8_DDU_package/HFL8_DDU/
		cp ../$PISUpdateBasePath/home/project/HFL8_DDU/alarmChannelConfig ./TC1_right/HFL8_DDU_package/HFL8_DDU/
		cp ../$PISUpdateBasePath/home/project/HFL8_DDU/alarmChannelConfig ./TC2_left/HFL8_DDU_package/HFL8_DDU/
		cp ../$PISUpdateBasePath/home/project/HFL8_DDU/alarmChannelConfig ./TC2_right/HFL8_DDU_package/HFL8_DDU/
		exit 0
	fi	
else
    echo "wrong paramaters.."
fi
